package org.shagin.jfin.ui.money;

import java.awt.FlowLayout;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import org.shagin.jfin.data.Money;
import org.shagin.jfin.ui.UI;

/**
 * The Class JMoneyPane.
 */
@SuppressWarnings("serial")
public class JMoneyPane extends JPanel {

    private Money money;
    private JTextField amount = new JTextField();

    /**
     * Instantiates a new j money pane.
     * 
     * @param money the money
     */
    public JMoneyPane() {
        super();
        setLayout(new FlowLayout(FlowLayout.CENTER, UI.HGAP, UI.VGAP));
        // TODO Localize
        add(new JLabel("Сумма"));
        amount.setColumns(10);
        add(amount);
    }

    /**
     * Gets the money.
     * 
     * @return the money
     */
    public Money getMoney() {
        money.setValue(Double.parseDouble(amount.getText()));
        return money;
    }

    /**
     * Sets the money.
     * 
     * @param money the new money
     */
    public void setMoney(Money money) {
        this.money = money;
        amount.setText(new Double(money.getValue()).toString());
    }

}
